<script setup lang="ts">
import { getPatentDetail } from "@/api/research/patent";
import { FileUpload } from "@/components/common/FileUpload";
import { formatDate, isCanPreview } from "@/utils/common";
import dayjs from "dayjs";
import { ref, watch } from "vue";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    patentName: "",
    patentNumber: "",
    acceptanceDate: "",
    acceptanceFiles: "",
    authorizeDate: "",
    authorizeFiles: "",
    firstInventor: "",
    firstInventorType: "",
    issueDate: "",
    issueFiles: "",
    obtainDate: "",
    obtainDateFiles: "",
    patentType: "",
    rewardLevel: "",
    rewardName: "",
    secondInventor: "",
    secondInventorType: "",
    showTwoInventor: false,
    transformFiles: "",
    obtainReward: null,
    transform: null,
    transformPrice: null,
    userIds: null,
    score: 0,
    examineStatus: 0,
    examineDesc: ""
  }),
  dataId: null,
  userList: null
});

watch(
  () => props.dataId,
  async newValue => {
    if (!newValue) {
      return;
    }
    getPatentDetail({ id: newValue }).then(res => {
      newFormInline.value = res.data;
    });
  },
  { immediate: true }
);

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    :model="newFormInline"
    :inline="true"
    class="add-form"
    label-width="110px"
  >
    <el-form-item label="专利名称" prop="patentName">
      <div>{{ newFormInline.patentName || "--" }}</div>
    </el-form-item>
    <el-form-item label="专利号" prop="patentNumber">
      <div>{{ newFormInline.patentNumber || "--" }}</div>
    </el-form-item>
    <el-form-item label="专利类型" prop="patentType">
      <div>{{ newFormInline.patentType || "--" }}</div>
    </el-form-item>
    <el-form-item />
    <el-form-item label="第一发明人类型" prop="firstInventorType">
      <div>{{ newFormInline.firstInventorType || "--" }}</div>
    </el-form-item>
    <el-form-item label="第一发明人" prop="firstInventor">
      <div>{{ newFormInline.firstInventor || "--" }}</div>
    </el-form-item>
    <template v-if="newFormInline.showTwoInventor">
      <el-form-item label="第二发明人类型" prop="secondInventorType">
        <div>{{ newFormInline.secondInventorType || "--" }}</div>
      </el-form-item>
      <el-form-item label="第二发明人" prop="secondInventor">
        <div>{{ newFormInline.secondInventor || "--" }}</div>
      </el-form-item>
    </template>

    <el-form-item label="专利所属国家" prop="belongCountry">
      <div>{{ newFormInline.belongCountry || "--" }}</div>
    </el-form-item>

    <el-form-item label="专利权人" prop="patentee">
      <div>{{ newFormInline.patentee || "--" }}</div>
    </el-form-item>
    <el-form-item label="受理日期" prop="acceptanceDate">
      <div>
        {{ formatDate(newFormInline.acceptanceDate) }}
      </div>
    </el-form-item>

    <el-form-item label="递交日期" prop="sendDate">
      <div>
        {{ formatDate(newFormInline.sendDate) }}
      </div>
    </el-form-item>
    <el-form-item label="授权日期" prop="authorizeDate">
      <div>
        {{ formatDate(newFormInline.authorizeDate) }}
      </div>
    </el-form-item>

    <!-- <el-form-item label="受理附件" prop="acceptanceFiles">
      <FileUpload v-model="newFormInline.acceptanceFiles" disabled />
    </el-form-item> -->
    <el-form-item label="授权附件" prop="authorizeFiles">
      <FileUpload
        v-model="newFormInline.authorizeFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <!-- <el-form-item label="下达日期" prop="issueDate">
      <div>
        {{
          newFormInline.issueDate
            ? dayjs(newFormInline.issueDate).format("YYYY-MM-DD")
            : "--"
        }}
      </div>
    </el-form-item>
    <el-form-item label="下达附件" prop="issueFiles">
      <FileUpload v-model="newFormInline.issueFiles" disabled />
    </el-form-item> -->

    <!-- 是否获奖 1获奖 0未获奖 -->
    <!-- <el-form-item label="是否获奖" prop="obtainReward">
      <div>{{ newFormInline.obtainReward == 1 ? "是" : "否" }}</div>
    </el-form-item> -->
    <el-form-item label="奖项名称" prop="rewardName">
      <div>{{ newFormInline.rewardName || "--" }}</div>
    </el-form-item>
    <el-form-item label="奖项级别" prop="rewardLevel">
      <div>{{ newFormInline.rewardLevel || "--" }}</div>
    </el-form-item>
    <el-form-item label="获奖日期" prop="obtainDate">
      <div>
        {{
          newFormInline.obtainDate
            ? dayjs(newFormInline.obtainDate).format("YYYY-MM-DD")
            : "--"
        }}
      </div>
    </el-form-item>
    <el-form-item label="获奖附件" prop="obtainDateFiles">
      <FileUpload
        v-model="newFormInline.obtainDateFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>

    <!-- 是否转化 1是 0否 -->
    <!-- <el-form-item label="是否转化" prop="transform">
      <div>{{ newFormInline.transform == 1 ? "是" : "否" }}</div>
    </el-form-item> -->
    <el-form-item label="转化金额" prop="transformPrice">
      <div>
        {{ newFormInline.transformPrice || "--" }}
        <span v-if="newFormInline.transformPrice">万元</span>
      </div>
    </el-form-item>
    <el-form-item label="转化附件" prop="transformFiles">
      <FileUpload
        v-model="newFormInline.transformFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="关联人员" prop="userIds">
      <div>
        {{
          userList && userList.length > 0
            ? userList.map(v => v.name).join(",")
            : "--"
        }}
      </div>
    </el-form-item>
    <el-form-item label="获取积分" prop="score">
      <div>{{ newFormInline.score || "--" }}</div>
    </el-form-item>
    <el-form-item label="审核状态" prop="score">
      <el-tag v-if="newFormInline.examineStatus === 0" type="warning"
        >审核中</el-tag
      >
      <el-tag v-else-if="newFormInline.examineStatus === 1" type="primary"
        >已审核</el-tag
      >
      <el-tag v-else type="danger">已驳回</el-tag>
    </el-form-item>
    <el-form-item label="驳回原因" prop="score">
      <div>{{ newFormInline.examineDesc || "--" }}</div>
    </el-form-item>
    <el-form-item />
  </el-form>
</template>
<style lang="scss" scoped>
.add-form {
  text-align: center;
  .el-form-item {
    width: 42%;
  }
}
</style>
